package com.lg.erp.controller.zhangkai;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.lg.erp.entity.JsonResult;
import com.lg.erp.entity.zhangkai.Customer;
import com.lg.erp.entity.zhangkai.Relation;
import com.lg.erp.service.zhangkai.ICustomerService;
import com.lg.erp.service.zhangkai.IRelationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.annotation.AliasFor;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

@RestController
public class CustomerController {
    @Autowired
    private ICustomerService customerService;

    @Autowired
    private IRelationService relationService;
    //分页查询客户
    @RequestMapping(value = "/customers",method = RequestMethod.GET)
    public JsonResult findPage(@RequestParam(value = "curr",required = false,defaultValue = "1")Long curr,@RequestParam(value = "size",required = false,defaultValue = "7")Integer size){
        Page<Customer> customerPage = new Page<>(curr,size);
        IPage<Customer> page = customerService.page(customerPage, null);
        return new JsonResult(1,"ok",page);
    }



    //条件模糊查询
    @RequestMapping(value = "/customer/condition",method = RequestMethod.POST)
    public JsonResult findByCondition(@RequestBody Customer customer){
        List<Customer> customerByCondition = customerService.findCustomerByCondition(customer);
        return new JsonResult(1,"ok",customerByCondition);
    }

    //新增客户
    @RequestMapping(value = "/customer",method = RequestMethod.POST)
    public JsonResult add(@RequestBody Customer customer){
        customerService.save(customer);
        return new JsonResult(1,"ok",null);
    }

    //更新客户
    @RequestMapping(value = "/customer",method = RequestMethod.PUT)
    public JsonResult modify(@RequestBody Customer customer,@RequestParam String curr){
        customerService.updateById(customer);
        return new JsonResult(1,"ok",curr);
    }
}
